import React, { useContext } from 'react';
import { Space, Button } from 'antd';
import '../common/updateStyle.less';
import { IActionEnum } from '../common/ExpertsReducer';
import { ExpertsUpdateContext } from '../common/ExpertsContext'
import {
    DoubleLeftOutlined,
    DoubleRightOutlined,
} from '@ant-design/icons';

const UpdateExpertsFold: React.FC = () => {
    const { prefixCls, activeKeys, dispatch } = useContext(ExpertsUpdateContext);

    /**
     * @collAllRemove
     * @description 折叠面板全选于反选
     * @param clickType 类型
     */
    const collAllRemove = (clickType: string) => {
        if (clickType == 'allOpen') {
            dispatch({
                type: IActionEnum.UPDATE_ACTIVE_KEY,
                payload: activeKeys
            })
        } else {
            dispatch({
                type: IActionEnum.UPDATE_ACTIVE_KEY,
                payload: []
            })
        }
    };
    return (
        <Space>
            <Button
                type={!activeKeys.length ? 'dashed' : 'primary'}
                size={'small'}
                icon={
                    <DoubleLeftOutlined className={`${prefixCls}conmpanyCardExtra`} />
                }
                className='manageBtntTxtStyle'
                onClick={() => { collAllRemove('allClose') }}
                disabled={!activeKeys.length ? true : false}
            >
                全部折叠
            </Button>
            <Button
                type={activeKeys.length ? 'dashed' : 'primary'}
                size={'small'}
                icon={
                    <DoubleRightOutlined className={`${prefixCls}conmpanyCardExtra`} />
                }
                className='manageBtntTxtStyle'
                onClick={() => { collAllRemove('allOpen') }}
                disabled={activeKeys.length == 3 ? true : false}
            >
                全部展开
            </Button>
        </Space>
    );
}
export default UpdateExpertsFold;